#ifndef RESTAURANTDATAMANAGER_H
#define RESTAURANTDATAMANAGER_H

/*
 The RestaurantDataManager will have responsibility to rend a request to google api
 The are two kind of send request with different purpose:
    - Get the location of user query
    - Get the nearby restaurants based on the location

 Because of two kind of request, so that it will have two kind of response as well, each response will
 be handled by differ datamanagerhelper.
*/
#include "place.h"


#include <QObject>
#include <QNetworkAccessManager>
#include <QVariantMap>


class RestaurantDataManager : public QObject
{
    Q_OBJECT

    friend class DataReceivedHandler;
    friend class LocationHandler;
    friend class PlacesDataHandler;
    friend class PlaceDetailsHandler;

public:
    explicit RestaurantDataManager(QObject *parent = 0);

signals:

    void errorOccured (const QString & error) const;
    void locationFound(const QString & location) const;
    void placeFound   (const QString & place_id) const;
    void placeDetailsFound(const Place& place_detail) const;

public slots:

    void searchLocationByAddress(const QString & apiKey, const QString &address);

    void searchRestaurantByLocation(
            const QString & apiKey, const QString & language,
            const QString & type,   const QString & location
    );

    void searchRestaurantDetails(
            const QString & apiKey, const QString & place_id,
            const QString & language = QString()
    );

private slots:

    void replyFinished(QNetworkReply * reply) const;

private:

    enum RequestType { Get, Post, Put, Delete };
    void sendRequest(
            const QString & url, class DataReceivedHandler * helper = 0,
            RequestType type = Get, const QByteArray & data = QByteArray()
    );
    bool existsReplyError(const QNetworkReply * reply) const;

    QNetworkAccessManager m_NetworkAccessManager;
};

#endif // RESTAURANTDATAMANAGER_H
